package com.wemake.controller;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.net.DatagramPacket;
import java.nio.charset.StandardCharsets;
import java.util.logging.Logger;

public class UDPEchoServerHandle extends SimpleChannelInboundHandler<DatagramPacket> {

    private static final Logger log = Logger.getLogger(UDPEchoServerHandle.class.getName());

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, DatagramPacket datagramPacket) throws Exception {
        byte[] msg = datagramPacket.getData();
        log.info("收到UDP数据：" + new String(msg, StandardCharsets.UTF_8));
        log.info("来自：" + channelHandlerContext.channel().remoteAddress());
    }
}
